﻿// ***************************************************************************
// MapLook
// Copyright (C) 2009 Christian Schmiljun
// http://maplook.codeplex.com
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// ***************************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MapLook2007
{
    public class MapVirtualEarth : MapService
    {
        private string location = null;
        private bool init = false;

        public MapVirtualEarth()
            : base()
        {
        }

        public override void SetLocationByDescription(string location)
        {
            this.location = location;           

            this.Navigate(new Uri("http://maps.live.com"));

            this.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(Web_DocumentCompleted);
        }

        void Web_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
        {
            if (!init)
            {                
                ((mshtml.IHTMLInputElement)this.Document.Body.GetElementsByTagName("input")["header_taskBar_placessearch"].DomElement).value = location;
                // TODO, not nice
                System.Threading.Thread.Sleep(1000);
                ((mshtml.IHTMLElement)this.Document.Body.GetElementsByTagName("input")["header_taskBar_placesbttn"].DomElement).click();             
                init = true;
            }
        }
    }
}
